//
//  Mp3Recorder.h
//  BloodSugar
//
//  Created by PeterPan on 14-3-24.
//  Copyright (c) 2014年 shake. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol Mp3RecorderDelegate <NSObject>
@optional
- (void)failRecord;
- (void)beginConvert;
- (void)endConvertWithMP3FileName:(NSString *)fileName;
@end

@interface Mp3Recorder : NSObject
@property (nonatomic, weak) id<Mp3RecorderDelegate> delegate;

- (id)initWithDelegate:(id<Mp3RecorderDelegate>)delegate;
- (void)startRecord;
- (void)stopRecord;
- (void)cancelRecord;

@end

//

@interface NSString (extension_count)

+ (int)countWordFromString:(NSString *)str;

@end

@implementation NSString (extension_count)

+(int)countWordFromString:(NSString *)str{
    
    unsigned i,l=0,a=0,b=0;
    NSInteger n = [str length];
    unichar c;
    
    for(i=0;i<n;i++){
        
        c=[str characterAtIndex:i];
        
        if(isblank(c)){
            
            b++;
            
        }else if(isascii(c)){
            
            a++;
            
        }else{
            
            l++;
        }
    }
    
    if(a==0 && l==0) {
        return 0;
    }
    return l+(int)ceilf((float)(a+b)/2.0);
}
@end